#pragma once
#include "binaryReader.h"
#include "BinaryWriter.h"

struct Packet
{
	char* buffer;
	int length;
};

enum ANALYZER_STATUS
{
	ANALYZER_STATUS_NONE,
	ANALYZER_STATUS_START_RECEIVE,
	ANALYZER_STATUS_RECEIVING,
};
struct PacketReceiveController
{
	bool isAvailable;
	char* buffer;
	int packetLength;
	int index;
};

struct PacketAnalyzController;

typedef void(*DataAddFunc)(PacketAnalyzController *pCtrl);

struct PacketAnalyzController
{
	ANALYZER_STATUS status;
	char *buffer;
	int length;
	int index;
	DataAddFunc addFunc;
	PacketReceiveController rcvCtrl;
};


#define PACKET_HEADER_SIZE (1+4)


extern void PacketAnalyzerInit(PacketAnalyzController *pCtrl);
extern void PacketAnalyzerClose(PacketAnalyzController *pCtrl);
extern int PacketAnalyzerAddData(PacketAnalyzController *pCtrl, char* buffer, int length, Packet *packet);
extern int PacketAnalyzerSetHeader(Packet *packet, char** buffer, int *length);